package org.bai.algorithm.util;

import org.bai.algorithm.entity.ListNode;

import java.util.concurrent.ThreadLocalRandom;

public class ListNodeUtil {

    public static final ListNode<Integer> buildInt(int size, int range) {
        ThreadLocalRandom current = ThreadLocalRandom.current();
        ListNode<Integer> result = new ListNode<>();
        ListNode<Integer> temporary = result;
        for (int i = 0; i < size; i++) {
            temporary.val = current.nextInt(range);
            if (i < size - 1) {
                temporary = temporary.buildNext();
            }
        }
        while (temporary.val == 0) {
            temporary.val = current.nextInt(range);
        }
        return result;
    }
}
